<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>可被 K 整除的最小整数</title>
</head>

<body>
  <script>
    var smallestRepunitDivByK = function (k) {
      if (k == 1) return 1;
      if (k % 2 == 0 || k % 5 == 0) return -1;
      let testNum = 1, ans = 1;
      while (testNum != 0) {
        testNum = (testNum * 10 + 1) % k;
        ans++;
      }

      return ans;
    };
    console.log(smallestRepunitDivByK(3));
  </script>
</body>

</html>